package com.thingsgrid.appmonitor.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.thingsgrid.appmonitor.entity.Application;
import com.thingsgrid.appmonitor.service.ApplicationService;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 应用状态监控控制器
 */
@RestController
@RequestMapping("appm")
@AllArgsConstructor
public class ApplicationController {
	private ApplicationService applicationService;

	/**
	 * 分页查询
	 */
	@GetMapping("/applicationByPage")
	@ApiOperation(value = "查看", notes = "传入deviceId", position = 1)
	public R<Page<Application>> deviceByPage(Page<Application> page, String deviceId) {
		Page<Application> pages = applicationService.applicationByPage(page, deviceId);
		return R.data(pages);
	}

	/**
	 * 应用删除
	 */
	@PostMapping("/remove")
	@ApiOperation(value = "删除", notes = "传入ApplicationId", position = 3)
	public R<Application> remove(String applicationId, String deviceId) {
		boolean status = applicationService.deleteByApplicationId(applicationId, deviceId);
		return R.status(status);
	}

	/**
	 * 应用禁用
	 */
	@PostMapping("/forbidden")
	@ApiOperation(value = "禁用", notes = "传入ApplicationId", position = 4)
	public R<Application> forbidden(String applicationId, String deviceId) {
		boolean status = applicationService.forbiddenByApplicationId(applicationId, deviceId);
		return R.status(status);
	}

	/**
	 * 应用启用
	 */
	@PostMapping("/start")
	@ApiOperation(value = "启用", notes = "传入ApplicationId", position = 5)
	public R<Application> start(String applicationId, String deviceId) {
		boolean status = applicationService.startByApplicationId(applicationId, deviceId);
		return R.status(status);
	}


}
